home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11480 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Borland C's tmpnam()
  5. Date: Sun, 24 Mar 96 13:18:15 GMT
  6. Organization: none
  7. Message-ID: <827673495snz@genesis.demon.co.uk>
  8. References: <AD75E5DC9668E2A52@mcdiala13.it.luc.edu> <Pine.A32.3.91.960322134158.23347A-100000@red.weeg.uiowa.edu> <AD78E5E796681EC58@mcdialb10.it.luc.edu> <827626790snz@genesis.demon.co.uk> <3154C0DF.6E90@iadfw.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <3154C0DF.6E90@iadfw.net> lfw@iadfw.net "Larry Weiss" writes:
  15.  
  16. >> "The tempnam function generates a string that is a valid file name and that
  17. >>  is not the name of an existing file."
  18. >> 
  19. >
  20. >I might have written the Standard to say "not the name of an existing file at
  21. >the time that the name was created".
  22.  
  23. I don't think that is necessary. IMHO "an existing file" can only refer to
  24. one that exists at the time, it cannot refer to something that may exist in
  25. the future. To put it another way if a file with that name does not exist
  26. until sometime later it is not "an existing file".
  27.  
  28. >  There is no guarantee that that
  29. > particular
  30. >name is somehow reserved against future use by other processes that may be
  31. > competing
  32. >with your C based process for file names.   Or am I wrong?
  33. >  (in other words if
  34. >your process doesn't hurry to open a file with that name, then all bets are off
  35. >about that name already being used to represent an existing file).
  36.  
  37. Right - I see nothing that forbids this race condition since all guarantees
  38. are based on whether the file exists or not. So it appears that tmpnam()
  39. alone is unsafe in a pre-emptive environment. Because of:
  40.  
  41. "The tmpnam function generates a different string each time it is called,
  42.  up to TMP_MAX times."
  43.  
  44. you have some guarantees about calling tmpnam() more than once in a
  45. single program invocation. However one program invocation can only affect the
  46. operation of another in a well-defined manner by altering its environment in
  47. a globally visible way, which pretty much comes down to file operations.
  48. Even those needn't be globally visible. Nevertheless it appears you can
  49. change a file under a program's feet and still have well-defined behaviour (*),
  50. as long as you don't try to open it more than once at the same time.
  51.  
  52. I suppose the question ultimately is whether you can create any sort
  53. of syncronisation between concurrent program invocations using standard C.
  54. The remove() function could be a possible starting point. If a file exists
  55. and 2 programs race to remove() it, is exactly one of them guaranteed to
  56. succeed (assuming remove() is a valid action on that file by those
  57. programs)? I don't think so.
  58.  
  59. * - if you can't perform any form of synchronisation in standard C then
  60. even this is not strictly true.
  61.  
  62. -- 
  63. -----------------------------------------
  64. Lawrence Kirby | fred@genesis.demon.co.uk
  65. Wilts, England | 70734.126@compuserve.com
  66. -----------------------------------------
  67.